package edu.hebeu.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import edu.hebeu.entity.Department;
import edu.hebeu.entity.Employee;
import edu.hebeu.entity.Overtime;
import edu.hebeu.mapper.DepartmentMapper;
import edu.hebeu.mapper.EmployeeMapper;
import edu.hebeu.service.DepartmentService;
import edu.hebeu.service.EmployeeService;
import edu.hebeu.service.OvertimeService;
import edu.hebeu.util.MTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("overtime")


public class OvertimeController {

    @Autowired
    private OvertimeService overtimeService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Resource
    private EmployeeService employeeService;
    //查看加班信息
    @RequestMapping("/{employeeNumber}/oneself.do")
    public  String  overtime(@PathVariable Integer employeeNumber,
                             @RequestParam Integer pageNo, Model  model){
        Page<Overtime> page=overtimeService.selectPag(employeeNumber,pageNo);
        model.addAttribute("page",page);
           return "admin/oneself_overtime";
       }
       //安排加班的页面先查询出来
       @RequestMapping("/toAdd.do")
       public  String toAdd(Model model){
         /*  EntityWrapper<Department> wrapper = new EntityWrapper<>();
           wrapper.orderBy("id",false);
           List<Department> dList = departmentService.selectList(wrapper);
           model.addAttribute("dList",dList);
           EntityWrapper<Employee> wrapper1 = new EntityWrapper<>();
           wrapper1.orderBy("id",false);
           List<Employee> eList = employeeService.selectList(wrapper1);
           model.addAttribute("eList",eList);*/
         /*  List<Department> dList=departmentService.selectLis();
           model.addAttribute("dList",dList);
           List<Employee>   eList=employeeService.selectLis();
           model.addAttribute("eList",eList);*/
           List<Department>  dList=departmentMapper.selectLis();
           model.addAttribute("dList",dList);
          List<Employee>  eList= employeeMapper.selectLis();
           model.addAttribute("eList",eList);
           return  "admin/overtime_add";
       }
    //安排加班的页面增加动作
    @RequestMapping(value = "/add.do",method = RequestMethod.POST)
    public  String add(Overtime overtime,String date){
        overtime.setDay(MTimeUtil.stringParse(date));
        //overtime.setEmployeeNumber(employee.getEmployeeNumber());
        //overtime.setDepartmentNumber(department.getDepartmentNumber());
        overtimeService.insert(overtime);
        return "forward:/overtime/+"+overtime.getEmployeeNumber()+"/oneself.do?pageNo=1";
    }
















}
